package cn.wonderland.basic.service.impl;

import cn.wonderland.basic.enm.ShopStateEnum;
import cn.wonderland.basic.service.EchartsService;
import cn.wonderland.basic.vo.EchartsMidVo;
import cn.wonderland.basic.vo.EchartsVo;
import cn.wonderland.org.mapper.ShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class EchartsServiceImpl implements EchartsService {

    @Autowired
    private ShopMapper shopMapper;

    /**
     * 报表
     *
     * @return
     */
    @Override
    public EchartsVo echarts() {
        EchartsVo vo = new EchartsVo();
        // 查询集合数据
        List<EchartsMidVo> echartsMidVoList = shopMapper.echarts();
        // 数据处理
        List<String> x = echartsMidVoList.stream().map(mid -> {
            return ShopStateEnum.getNameByCode(mid.getX());
        }).collect(Collectors.toList());
        vo.setX(x);
        List<Integer> y = echartsMidVoList.stream().map(EchartsMidVo::getY).collect(Collectors.toList());
        vo.setY(y);
        return vo;
    }
}
